<?php
declare (strict_types=1);

namespace app\speedDating\middleware;

use app\speedDating\interfaces\KeyName;
use app\speedDating\services\common\JWTAuthUserService;
use app\speedDating\services\common\JWTService;
use think\facade\Cache;

class AuthorizationMiddleware
{
    /**
     * 处理请求
     * @param $request
     * @param \Closure $next
     * @return mixed
     * @throws \Psr\SimpleCache\InvalidArgumentException
     */
    public function handle($request, \Closure $next)
    {
        $authorization = $request->header(KeyName::AUTHORIZATION);

        $result = JWTService::verify($authorization);

        JWTAuthUserService::register($result);

        return $next($request);
    }

}
